<template>
	<!-- 考试成绩选择 -->
	<u-popup :show="_show" @close="onClose">
		<view class="top-action fboxCol Ycenter Xcenter">
			<view class="fboxRow Ycenter w690 font26">
				<view class="fboxRow Ycenter Xcenter color-9899A1" @tap="onClose">取消</view>
				<view class="flex1 fboxRow Ycenter Xcenter font30 color-36363A">
					{{student.studentName}}，请选择你所参加的考试
				</view>
				<view class="fboxRow Ycenter Xcenter color-00C15D" :loading="loading" @tap="onSubmit">查询</view>
			</view>
		</view>
		<view class="filter-item fboxWrap Ycenter Xcenter">
			<view>
				<block v-if="examList.length">
					<view v-for="(subItem,index) in examList" :key="index">
						<view class="tag fboxRow Ycenter Xcenter font28"
							:class="curItem.examId == subItem.examId ? 'on color-00C15D' : 'color-9899A1'"
							@tap="tagClick(subItem)">{{subItem.examName}}</view>
					</view>
				</block>
				<view class="fboxRow Ycenter Xcenter color-9899A1 font24" v-else>暂无考试</view>
			</view>
		</view>
	</u-popup>
</template>

<script>
	import {allExamList} from '@/api/bks.examinee.js'
	import {sameName} from '@/api/bks.index.js'
	export default {
		props: {
			scoreList: {
				type: Object,
				default: ()=>{
					return {}
				}
			},
			show: {
				type: Boolean,
				default: true
			},
			student: {
				type: Object,
				default: ()=>{
					return {}
				}
			}
		},
		components: {},
		computed:{
			_show:{
				get(){
					return this.show
				},
				set(val){
					this.$emit('update:show',val)
				}
			}
		},
		data() {
			return {
				curExam: '',
				curName: '',
				loading: false,
				examList: [],
				curItem: {
					examId: "",
					examName: "",
					examTime: "",
				}
			}
		},
		watch:{
			show:{
				handler(val){
					if(val){
						this.getExam()
					}
				},
				deep: true,
				immediate: true
			}
		},
		methods: {
			// 修改成绩
			getExam(){
			  const {gradeId, unitId} = this.student
			  allExamList().then(exam => {
				  this.examList = exam.data
			  })
			},
			//  选择科目
			tagClick(item){
			  this.curItem= item
			},
			// 取消
			cancelTap(){
			  this.onClose()
			},
			// 隐藏
			onClose(){
				this._show = false
			},
			// 确定选科
			onSubmit(){
			  const {studentCode, studentName, unitId} = this.student
			  const {curItem} = this
			  if(this.curItem && this.curItem.examId){
				sameName({
				  examId: this.curItem.examId,
				  studentCode,
				  studentName,
				  unitId
				}).then(res => {
				  if(res.data.length == 0){
					uni.showToast({
					  title: '暂无学生成绩',
					  icon: 'none'
					})
				  }else if(res.data.length >= 2){
					this.$pageTo('/bks/index/score/studentInfo/sameName/index', {
					  examId: curItem.examId,
					  examName: curItem.examName,
					  examTime: curItem.examTime,
					  studentName,
					  unitId,
					  studentCode
					})
					this.$emit('on-exam')
				  }else{
					this.$pageTo('/bks/volunteer/myScore/detail/index', {
					  examId: curItem.examId,
					  examName: curItem.examName,
					  examTime: curItem.examTime,
					  studentCode: res.data.length ?  res.data[0].studentCode : studentCode
					})
					this.curItem = {}
					this.$emit('on-exam')
				  }
				})
			  }else{
				wx.showToast({
				  title: '请选择考试',
				  icon: 'none',
				  duration: 2000
				})
			  }
			}
		}
	}
</script>

<style lang="scss" scoped>
	
.score-item{margin-top: 10rpx;border-bottom: 1px solid #EBEBF0;}
.score-item .hd{height: 84rpx;border-bottom: 1px solid #EBEBF0;}
.score-item .hd .dot{margin-right: 10rpx; width: 12rpx;height: 12rpx;border-radius: 50%;}
.bg-3480FF{background-color: #3480FF;}
.bg-FFBC44{background-color: #FFBC44;}
.score-item .bd{padding: 20rpx 0;}
.score-item .ft{height: 80rpx;border-top: 1px solid #EBEBF0;}
.score-item .ft .bksCIcon{transform:rotate(0deg); transition: transform .3s;}
.score-item .ft .bksCIcon.unfold{transform:rotate(180deg);}
.score-item .score-tag{padding: 15rpx 0;width: 230rpx;}
.score-item .score-tag .con{margin-top: 20rpx;}

.plus-class{background: none !important;}
.input-class{background: none !important;}
.minus-class{background: none !important;}

.filter-item{ height: 570rpx;overflow-y: auto;}
/* .filter-item .tit{margin-bottom: 20rpx;height: 80rpx;} */
.filter-item .tag{margin:0  auto 20rpx;width: 494rpx;
  height: 80rpx;
  background: #FFFFFF;
  border: 1px solid #EBEBF0;
  border-radius: 8rpx;
  }

.filter-item .on{
  background: #F5FAF7;
  border: 1px solid #00C15D;}

.top-action{height: 88rpx;}
/* .top-action .fixed{position: absolute;left: 0;top:0; padding: 0 30rpx;} */
.top-action .colse{background-color: #fff;}
.top-action .filter{background-color: #00C15D;}
.top-action .btn{ width: 335rpx; height: 84rpx;border-radius: 8rpx; border:0 none !important}
.top-action .btn-00C15D{margin-right: 20rpx; border: 1px solid #00C15D !important;}
  
</style>